<template>
  <div>
    <div class="table">
      <el-table :data="tableData" show-overflow-tooltip>
        <el-table-column type="index" align="center" label="序号" width="70" />
        <el-table-column label="需求岗位数量" prop="demandJobs">
        </el-table-column>
        <el-table-column prop="requireProposerName" label="需求申请人" />
        <el-table-column prop="requireDeptName" label="需求部门" />
        <el-table-column prop="requireJobOverview" label="岗位需求概述" />
        <el-table-column prop="hopeArrivalTime" label="期望到岗日期" />
        <el-table-column prop="closeTime" label="截止日期" />
        <el-table-column prop="proposeTime" label="申请日期" />
        <el-table-column prop="status" label="状态" />
        <el-table-column label="操作" width="180">
          <template #default="scope">
            <el-button
              class="other-btn"
              type="text"
              size="small"
              @click="handleInfo(scope.row)"
              >查看</el-button
            >
            <el-button
              class="other-btn"
              type="text"
              size="small"
              v-if="isShowBtn"
              @click="handleEdit(scope.row)"
              >编辑</el-button
            >
            <el-button
              class="other-btn"
              v-if="isApproval && scope.row.todo"
              type="text"
              size="small"
              @click="handleWork(scope.row)"
              >审批</el-button
            >
            <el-button
              class="del-button"
              type="text"
              size="small"
              v-if="isShowBtn"
              @click="handleDelete(scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <Pagination
      :total="pagination.total"
      :page="pagination.page"
      :limit="pagination.limit"
      :pageSizes="pagination.pageSizes"
      @handleSizeChange="sizeChange"
      @handleCurrentChange="currentChange"
    ></Pagination>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted, onBeforeUnmount } from "vue";
import { getCommonTableHeight } from "@/utils/commonTableHeight.js";

import Pagination from "@/components/Pagination/pageination.vue";
const props = defineProps({
  isShowBtn: Boolean,
  isApproval: Boolean,
  tableData: Array,
  pagination: {
    type: Object,
    required: true,
    default: () => ({
      total: 10,
      page: 1,
      limit: 10,
      pageSizes: 10,
    }),
  },
});
const emit = defineEmits([
  "sizeChange",
  "currentChange",
  "handleInfo",
  "handleEdit",
  "handleWork",
  "handleDelete",
]);

const tabHeight = ref(0);

// 页面高度
const updateViewportHeight = () => {
  tabHeight.value = getCommonTableHeight();
};
onMounted(() => {
  updateViewportHeight(); // 初始化视口高度
  window.addEventListener("resize", updateViewportHeight); // 监听窗口大小变化
});

onBeforeUnmount(() => {
  window.removeEventListener("resize", updateViewportHeight); // 移除监听
});

const handleInfo = (row) => {
  emit("handleInfo", row);
};
const sizeChange = (size) => {
  console.log(size, "size");
  emit("sizeChange", size);
};
const currentChange = (page) => {
  console.log(page, "1");
  emit("currentChange", page);
};
// 编辑
const handleEdit = (row) => {
  emit("handleEdit", row);
};
// 审批
const handleWork = (row) => {
  emit("handleWork", row);
};
// 删除
const handleDelete = (row) => {
  emit("handleDelete", row);
};
</script>

<style lang="scss" scoped>
// :deep(.el-table__header) {
//   height: 70px;
// }
.elTag {
  color: #fff;
  font-size: 13px;
  font-weight: 500;
}
.btn {
  font-size: 15px;
  padding: 0;
}
</style>
